package com.ruoyi.system.controller;


import java.math.BigDecimal;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ruoyi.system.mapper.InfiniteGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InfiniteGoods;
import com.ruoyi.system.service.IInfiniteGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 无限赏信息Controller
 * 
 * @author ruoyi
 * @date 2022-05-24  TODO  充值
 */
@RestController
@Slf4j
@RequestMapping("/system/in-goods")
public class InfiniteGoodsController extends BaseController
{
    @Autowired
    private IInfiniteGoodsService infiniteGoodsService;

    @Resource
    private InfiniteGoodsMapper infiniteGoodsMapper;





//    @PostMapping("/copyInfiniteGoods")
//    public AjaxResult copyInfiniteGoods(@RequestParam("goodsId")
//                                        Integer infiniteGoodsId)
//    {
//
//
//
//        return AjaxResult.success();
//    }

    /**
     * 查询无限赏信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfiniteGoods infiniteGoods)
    {
        startPage();
        List<InfiniteGoods> list = infiniteGoodsService.selectInfiniteGoodsList(infiniteGoods);
        return getDataTable(list);
    }

    /**
     * 导出无限赏信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:export')")
    @Log(title = "无限赏信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfiniteGoods infiniteGoods)
    {
        List<InfiniteGoods> list = infiniteGoodsService.selectInfiniteGoodsList(infiniteGoods);
        ExcelUtil<InfiniteGoods> util = new ExcelUtil<InfiniteGoods>(InfiniteGoods.class);
        util.exportExcel(response, list, "无限赏信息数据");
    }

    /**
     * 获取无限赏信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(infiniteGoodsService.selectInfiniteGoodsById(id));
    }

    /**
     * 新增无限赏信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "无限赏信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfiniteGoods infiniteGoods)
    {
        int goodsId = infiniteGoodsService.insertInfiniteGoods(infiniteGoods);

        return AjaxResult.success("新增无限赏成功！");
    }

    /**
     * 修改无限赏信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "无限赏信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfiniteGoods infiniteGoods)
    {
        log.info("修改无限赏信息 infiniteGoods is {}", JSON.toJSONString(infiniteGoods));
        return toAjax(infiniteGoodsService.updateInfiniteGoods(infiniteGoods));
    }


    @PostMapping("/updateInfiniteGoodsJc")
    public AjaxResult updateInfiniteGoodsDisCount(@RequestParam("goodsId")
                                                  Integer goodsId, @RequestParam("jc")
                                                      BigDecimal disCount)
    {

        return AjaxResult.success( infiniteGoodsMapper.updateInfiniteGoodsDisCount(goodsId, disCount));
    }

    /**
     * 删除无限赏信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "无限赏信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(infiniteGoodsService.deleteInfiniteGoodsByIds(ids));
    }
}
